package ru.st.selenium.pages;

import static org.openqa.selenium.support.ui.ExpectedConditions.presenceOfElementLocated;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.ui.Select;

public class MovieManagementPage extends InternalPage {

	public MovieManagementPage(PageManager pages) {
		super(pages);
	}
	
	@FindBy(name = "imdbsearch")
	private WebElement imdbsearchField;
	
	@FindBy(name = "name")
	private WebElement nameField;
	
	@FindBy(name = "year")
	private WebElement yearField;
	
	@FindBy(name = "submit")
	private WebElement submitButton;
	
	public String getImdbname() {
	    return imdbsearchField.getAttribute("value");
	  }
	
	public String getTitlename() {
		    return nameField.getAttribute("value");
		  }

	public MovieManagementPage setTitleField(String text) {
	    nameField.sendKeys(text);
	    return this;
	  }
	
	public String getYearname() {
		    return yearField.getAttribute("value");
		  }
	
	public MovieManagementPage setYearname(String text) {
	    yearField.sendKeys(text);
	    return this;
	  }
	
	
	public MovieManagementPage clickSubmitButton() {
			submitButton.click();
			return this;
		  }
	public MovieManagementPage name(String text) {
	    nameField.sendKeys(text);
	    return this;
	  }
	
	public MovieManagementPage ensurePageLoaded() {
		    super.ensurePageLoaded();
		    wait.until(presenceOfElementLocated(By.cssSelector("img[alt=\"Save\"]")));
		   // wait.until(presenceOfElementLocated(By.cssSelector("div.content h3")));
		    return this;
		  }

	
}